<%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib uri="http://util.paginationtag" prefix="pagination-tag"%>
<%@ page contentType="text/html; charset=UTF-8" %>
<decorator:usePage id="mainPage" />
<html>
<head>
<link href="<s:url value='/css/not-ie.css' />" rel="stylesheet" type="text/css">
<link href="<s:url value='/css/pagination.css' />" rel="stylesheet" type="text/css">
<script language="javascript">
function sf(){
	document.getElementsByName("criteria.userName")[0].focus();
}
	function searchPage(){
		frm = document.userForm;
		frm["criteriaKey"].value = "";
		frm.action = "<s:url value='/searchUser.action'/>";
		frm.submit();
		}

	function gotoAdd(){
			frm = document.userForm;
			frm.action = "<s:url value='/gotoAddUser.action'/>";
			frm.submit();
		}

	function gotoEdit(id){
		frm = document.userForm;
		//set ค่า id ลงใน member.memberId
		frm.action = "<s:url value='/searchByIdUser.action'/>?userId="+id+"&page=edit";
		frm.submit();
		}

	function gotoView(id){
		frm = document.userForm;
		//set ค่า id ลงใน member.memberId
		frm.action = "<s:url value='/searchByIdUser.action'/>?userId="+id+"&page=view";
		frm.submit();
		}

	function deletes(chkName){
		var chk = false;
		chk = chkSellock(chkName);
		if(chk == false){alert('<s:text name="0007" />');return;}
		if(!confirm('<s:text name="0008" />')){
			return false;
		} 
		var ids="";
		for(i=0;i<document.getElementsByName(chkName).length;i++){
			if(document.getElementsByName(chkName)[i].checked==true){
				ids+=","+document.getElementsByName(chkName)[i].value;
			}
		}
	      
		frm = document.userForm;
		frm.action="<s:url value='/deleteUser.action' />?userIds="+	ids.substring(1);
		frm.submit();
	}
	function clearPage(){
		frm = document.userForm;
		frm.action="<s:url value='/clearIUser.action'/>";
		frm.submit();
	}
	function switchAll(chkName,val){
		var chk = document.getElementsByName(chkName);
		for (var i=0; i<chk.length; i++){
			if(chk[i].disabled != true){//enable object
				chk[i].checked = val;
			}
		}
	}
	function chkSellock(chkName){
		var chk = document.getElementsByName(chkName);
		for (var i=0; i<chk.length; i++)
		{if (chk[i].checked == true) {return true;}}
		return false;
	}
	function checkID(id) {
		if (id.length != 13)
			return false;
		for (i = 0, sum = 0; i < 12; i++)
			sum += parseFloat(id.charAt(i)) * (13 - i);
		if ((11 - sum % 11) % 10 != parseFloat(id.charAt(12)))
			return false;
		return true;
	}

	function checkForm(id) {
		if (!checkID(id)){
			alert('รหัสประชาชนไม่ถูกต้อง');
		    document.getElementsByName("criteria.peopleId").value = "";
		}else{
			alert('รหัสประชาชนถูกต้อง เชิญผ่านได้');
		}
	}
</script>
</head>
<body>
<h1>ค้นหาผู้ใช้</h1>
<s:form method="post" id="userForm" name ="userForm" onsubmit="searchPage();">
<s:submit cssClass="submit" id="submitId"/>
	<table class="authen">
		<tr>
			<td class="left"></td>
			<td class="center"><s:property value="#request.message" /></td>
			<td class="right"></td>
		</tr>
	</table>
	<table class="form" border="0">
		<tr style="height: 0px;">
			<td class="col-width-100px"></td>
			<td class="col-width-175px"></td>
			<td class="col-width-175px"></td>
			<td class="col-width-175px"></td>
			<td class="col-width-175px"></td>
			<td class="col-width-auto"></td>
		</tr>
		
		<tr><td></td> </tr>
		<tr>
			<td></td>
			<td align="right">ชื่อผู้ใช้&nbsp;&nbsp;&nbsp;&nbsp;</td>
			<td><s:textfield name="criteria.userName"/></td>
			<td align="right">ชื่อ&nbsp;&nbsp;&nbsp;&nbsp;</td>
			<td><s:textfield name="criteria.name"/></td>
		</tr>
		<tr>
			<td></td>
			<td align="right">นามสกุล&nbsp;&nbsp;&nbsp;&nbsp;</td>
			<td><s:textfield name="criteria.surName"/></td>
			<td align="right">เลขประจำตัวบัตรประชาชน&nbsp;&nbsp;&nbsp;&nbsp;</td>
			<td><s:textfield name="criteria.peopleId"  maxlength="13" onchange="checkForm(this.value)"/></td>
		</tr>
		<tr>
			<td></td>
			<td align="right">โทรศัพท์มือถือ&nbsp;&nbsp;&nbsp;&nbsp;</td>
			<td><s:textfield name="criteria.mobile"/></td>
			<td align="right">โทรศัพท์บ้าน&nbsp;&nbsp;&nbsp;&nbsp;</td>
			<td><s:textfield name="criteria.phone"/></td>
		</tr>
		<tr>
			<td></td>
			<td align="right">สถานะการใช้งาน&nbsp;&nbsp;&nbsp;&nbsp;</td>
			<td>
				<s:select name="criteria.status" 
				headerKey=""
				headerValue="%{getText('msg.all')}" 
				list="#{'1':'ใช้งาน', '2':'ยกเลิก'}" 
				size="1" />	
			</td>
			<td></td>
			<td></td>
		</tr>
	</table>
	<table class="button">
		<tr>
			<td class="left"></td>
			<td class="right"> 
				<input  type="button" id="btnSearch" onclick="javascript:searchPage();" value="<s:text name="msg.search"></s:text>" class="btnSearch" />
				<input  type="button" id="btnClear" onclick="javascript:clearPage();" value="<s:text name="msg.clearScreen"></s:text>" 
					onkeydown="return doTabFocus('employeeCode','',event,true);"  class="btnClear" />
			</td>
		</tr>
	</table>	
	<s:if test="%{lstUserSearch.size() > 0}">
	<div  style="width:100%;  overflow-x: scroll;height: 260px; overflow-y:hidden;border:0px;">
		<table class="result" >
				<thead>
					<tr>
						<th class="order"><s:text name="no" /></th>
						<th class="checkbox"><input type="checkbox" 	name="chkAll"	onClick="switchAll('userIds',checked)" /></th>
						<th class="col-width-100px"><s:text name="ชื่อ" /></th>
						<th class="col-width-100px"><s:text name="นามสกุล" /></th>
						<th class="col-width-100px"><s:text name="เลขที่บัตรประชาชน" /></th>
						<th class="col-width-200px"><s:text name="ที่อยู่" /></th>
						<th class="col-width-100px"><s:text name="โทรศัพท์มือถือ" /></th>
						<th class="col-width-100px"><s:text name="โทรศัพท์บ้าน" /></th>
						<th class="col-width-100px"><s:text name="สถานะใช้งาน" /></th>
						<th  class="edit"><s:text name="แก้ไข" /></th>
						<th  class="view"><s:text name="แสดง" /></th>
						
					</tr>
				</thead>
		</table>
		<div style="border-left:none;overflow-y:scroll;overflow-x:hidden;height:220px;*height:215px;width:1100px;">
		<table class="result">
				<tbody>
					<s:iterator value="lstUserSearch" status="status" var="lstUserSearch">
						
						<tr >
							<td class="order"><s:property value="#status.index+1"/></td>
							<td class="checkbox">
									<input type="checkbox"	name="userIds" value="<s:property value='#lstUserSearch.userId' />" />
							</td>
							<td class="col-width-100px text" style="text-align: center;">
								<s:property value="#lstUserSearch.name"/>
							</td>
							<td class="col-width-100px text">
								<s:property value='#lstUserSearch.surName' />
							</td>
							<td class="col-width-100px text">
								<s:property value='#lstUserSearch.peopleId' />
							</td>
							<td class="col-width-200px text">
								<s:property value='#lstUserSearch.address' />
							</td>
							<td class="col-width-100px text">
								<s:property value='#lstUserSearch.mobile' />
							</td>
							<td class="col-width-100px text">
								<s:property value='#lstUserSearch.phone' />
							</td>
							<td class="col-width-100px text" style="text-align: center;">
								<s:if test='#lstUserSearch.status == "1"'>
									<img src="<s:url value='/images/icon/i_disable.gif'/>">&nbsp;<s:text name="active" />
								</s:if>
								<s:else>
									<img src="<s:url value='/images/icon/i_disable_dis.gif'/>">&nbsp;<s:text name="cancle" />
								</s:else>
							</td>
							<td class="edit">
								<a href="javascript:void(0);" onclick="javascript:gotoEdit('<s:property value='#lstUserSearch.userId' />');">
									<img src="<s:url value='/images/icon/i_edit.gif'/>">
								</a>
							</td>
							<td class="view">
								<a href="javascript:void(0);" onclick="javascript:gotoView('<s:property value='#lstUserSearch.userId' />');">
									<img src="<s:url value='/images/icon/i_view.gif' />">
								</a>
							</td>

						</tr>
					</s:iterator>
				</tbody>
			</table>
		</div>
		</div>
		<table class="result">
	<tfoot>
		<tr class="footer">
			<td>
				<a class="action-link" href="javascript:void(0);"  onclick="javascript:deletes('userIds');"><img src="<s:url value='/images/icon/i_del.gif' />">&nbsp;<s:text name="msg.delettb" /></a>&nbsp;&nbsp;
			</td>
		</tr>
	</tfoot>
</table>
	</s:if>
	<s:hidden name="criteriaKey"/>
</s:form>
</body>
</html>